--使用方法：直接粘贴到模组环境 ~打开控制台 输入 c_ifclear(400)  即删除周围半径100格地皮大部分实体
--来自群鸟绘卷

function _G.c_ifclear(r)    --清理周围  --参考群鸟绘卷
    local player = ConsoleCommandPlayer()
    local function InInv(b) 
        local inv = b.components.inventoryitem 
        return inv and inv.owner or false 
    end 
    local function CanDelete(inst) 
        if inst and inst ~= TheWorld and not InInv(inst) and inst.Transform and not inst:HasTag("huxi") and not table.contains({"multiplayer_portal", "multiplayer_portal_moonrock"}, inst.prefab) then 
            if inst:HasTag("player") then 
                return inst.userid == nil or inst.userid == ""
            else 
                return true 
            end 
        end 
        return false 
    end 

    if player and player.Transform then 
        if player.components.burnable then 
            player.components.burnable:Extinguish(true) 
        end 
        local x,y,z = player.Transform:GetWorldPosition() 
        local ents = TheSim:FindEntities(x,y,z, r or 28) 
        for _, obj in pairs(ents) do 
            if CanDelete(obj) then 
                if obj.components then 
                    if obj.components.burnable then obj.components.burnable:Extinguish(true) end 
                    if obj.components.firefx then 
                        if obj.components.firefx.extinguishsoundtest then 
                            obj.components.firefx.extinguishsoundtest = function() 
                                return true 
                            end 
                        end obj.components.firefx:Extinguish() 
                    end 
                end 
                if (not (obj.prefab == "minerhatlight" or "lanternlight" or "yellowamuletlight" or "slurperlight" or "redlanternlight" or "lighterfire" or "torchfire" or "torchfire_rag" or "torchfire_spooky" or "torchfire_shadow")) or (obj.entity:GetParent() == nil) then 
                    obj:Remove() 
                    --print(obj.prefab)
                end 
            end 
        end 
    end
end